package offer;

/**
 * 描述:剑指 Offer 53 - II. 0～n-1中缺失的数字
 *
 * @author Madison You
 * @created 0:03
 */
public class Easy_53_MissingNumber {
    public static void main(String[] args) {
        System.out.println(new Easy_53_MissingNumber().missingNumber(new int[]{0,2,3,4}));
    }

    public int missingNumber(int[] nums) {
        if (nums.length == 1) return 1;
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            int mid = (left + right) / 2;
            if (nums[mid] != mid) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return nums[left] - 1;
    }
}
